<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title th:text="${title}"></title>

<div th:include="/common/layui"></div>
<div th:include="/common/jq"></div>

<!--添加 layui 自己的 css js  支持加载-->
<link href="/css/houtai/manage_base.css"	rel="stylesheet" />
<script	src="/js/houtai/manage_base.js"></script>
<!--添加 layui 自己的 css js  支持加载-->

</head>

<script>
//定义在外面。可以代码中  使用 table
var table;
layui.use([ 'laydate', 'laypage', 'layer','form', 'table', 'carousel',
			'upload', 'element' ], function() {
	table = layui.table;
});

var global_ids;
var global_ids_len;

var w ;//窗口的宽
var h ;//窗口的高

//添加
function add(){
	w = 600;
	h = 500;
	checkWindow();
	//iframe层
	layer.open({
	  type: 2,
	  title: '添加',
	  shadeClose: false,
	  shade: 0.8,
	  area: [w+'px', h+'px'],
	  content: '/houtai/user/add' //iframe的url
	});
}


//打开编辑窗口
function edit(id){
	w = 600;
	h = 500;
	checkWindow();
	layer.open({
	  type: 2,
	  title: '修改',
	  shadeClose: false,
	  shade: 0.8,
	  area: [w+'px', h+'px'],
	  content: '/houtai/user/edit?id='+id //iframe的url
	});
}

function set_new_pwd(id){
	w = 600;
	h = 500;
	checkWindow();
	layer.open({
	  type: 2,
	  title: '设置新密码',
	  shadeClose: false,
	  shade: 0.8,
	  area: [w+'px', h+'px'],
	  content: '/houtai/user/set_new_pwd?id='+id //iframe的url
	});
}

//子窗口调用 的  关闭窗口方法 
function closeDlg(msg){
	 layer.closeAll();
	 layer.msg(msg);
	 reload_data();
}

//相当前刷新  重新加载
function reload_data(){
  table.reload('table', {
		where: {
	     },page: {curr: 1 //重新从第 1 页开始
				}
    });
}

function del(ids){
	var index = layer.load(1, {
		  shade: [0.1,'#fff'] //0.1透明度的白色背景
	});
	$.post('/admin/user/delete',{ids:ids},function(result){
		if(result.success){
			layer.closeAll();
			layer.msg('删除成功');
			reload_data();
		}else{
			layer.closeAll();
			layer.msg(result.msg);
		}
	},'json');
}

</script>
<body style="padding-top: 3px;">

<div class="layui-table-toolbar" style="margin-bottom: 3px; ">
	<div class="layui-btn-group">
		<button onclick="add()"  class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe654;</i>添加</button>
		<button onclick="delSelected()" class="layui-btn layui-btn-sm layui-btn-danger"><i class="layui-icon">&#xe640;</i>删除</button>
	    <button class="layui-btn layui-btn-sm" onclick="reload_data()"><i class="layui-icon">&#xe669;</i>刷新</button>
 	 </div>
</div>

<table class="layui-hide"   id="table" lay-filter="table"></table>

</body>

<script type="text/html" id="table_bar">
<div class="layui-btn-group">
	<a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
	<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="set_new_pwd">修改密码</a>
</div>
</script>

<script type="text/html" id="format_role">
{{#  if(d.role){ }}
{{d.role.name}}
{{#  } else {  }}
空白
{{#  }   }}
</script>

<script th:inline="none">
/*<![CDATA[*/
		layui.use([ 'laydate', 'laypage', 'layer', 'table', 'carousel',
				'upload', 'element' ], function() {
			var laydate = layui.laydate //日期
			, laypage = layui.laypage //分页
			,layer = layui.layer //弹层
			, table = layui.table //表格
			, carousel = layui.carousel //轮播
			, upload = layui.upload //上传
			, element = layui.element; //元素操作
			  table.render({
			    elem: '#table'
			    ,url: '/admin/user/list'
			    ,height: 'full-40'
			    ,totalRow: true
				,cols: [[
			       {checkbox: true, fixed: true}
				   
			       ,{field:'orderNo', title: '排序号', width:'10%',style:'font-size: 12px;' }
			       
			      ,{field:'name', title: '用户名', width:'15%',style:'font-size: 12px;' }
			      /*,{field:'trueName', title: '真实姓名', width:90,style:'font-size: 12px;' }*/
			      ,{field:'roleId', title: '角色', width:'15%',style:'font-size: 12px;',templet: '#format_role' }
			      
			    /*  ,{field:'remark', title: '备注', width:100 ,style:'font-size: 12px;'}*/
			      ,{field:'createDateTime', title: '创建时间', width:'15%' ,style:'font-size: 12px;'}
			      ,{field:'updateDateTime', title: '修改时间', width:'15%' ,style:'font-size: 12px;'}
			      
			      ,{fixed:'right', width:'15%',title: '操作',  toolbar: '#table_bar'}
			       ]]
			    ,id: 'table'
			    ,page: true
			    ,limits:[10,20,30,50],
			   limit:10
			  });
			
			//监听工具条 table_bar
				table.on('tool(table)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
					var data = obj.data //获得当前行数据
					, layEvent = obj.event; //获得 lay-event 对应的值
					if (layEvent === 'edit') {
						edit(data.id);
					} else if(layEvent === 'set_new_pwd'){
						set_new_pwd(data.id);
					}
				});
				
		});
		/*]]>*/
</script>



</html>